package com.leyou.task;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

//@Component
@Slf4j
public class JobTest {

    int times = 0;
/*

//    @Scheduled(fixedDelayString = "2000")   //任务出现累积fixedDelay会丢失任务
    @Scheduled(fixedDelay = 2000)   //任务出现累积fixedDelay会丢失任务
    public void test1(){
        if(times==1){
            try {
                Thread.sleep(4000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        log.debug("test1的方法");
        times++;
    }
*/

    @Scheduled(fixedRate = 2000)  //任务出现累积fixedRate不会丢失任务
//    @Scheduled(fixedRateString = "2000")  //任务出现累积fixedRate不会丢失任务
    public void test2(){
        if(times==1){
            try {
                Thread.sleep(4000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        log.debug("test2的方法");
        times++;
    }


    @Scheduled(cron = "0/2 * * * * ?")  //任务出现累积fixedDelay会丢失任务
    public void test3(){
        if(times==1){
            try {
                Thread.sleep(4000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        log.debug("test3的方法");
        times++;
    }


}
